package com.kele.unsafe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author kele
 * @date 2021/10/11 15:02
 * @description
 */
public class MapTest {
    public static void main(String[] args) {

        /**
         * 1.Map<String, Object> map=new HashMap<>(16);不安全
         * 2.Map<String, Object> map= Collections.synchronizedMap(new HashMap<>(16));安全
         * 3.Map<String, Object> map= new ConcurrentHashMap<>(16);并发包下的map集合 安全
         */
        Map<String, Object> map= new ConcurrentHashMap<>(16);
        for (int i = 0; i <30 ; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString());
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
